import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'
import router from './router'

// 检查登录状态
const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'
console.log('main.js: 登录状态检查:', isLoggedIn ? '已登录' : '未登录')

// 如果未登录，确保重定向到登录页
if (!isLoggedIn) {
  router.push('/login')
}

const app = createApp(App)

// 全局注册所有 Element Plus 图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(ElementPlus, {
  locale: zhCn,
})
app.use(router)
app.mount('#app')
